# 1、定义元组
t = (1, 'Jagochan', 6.6, True, [6, 7, 8])
empty_tuple1 = ()
empty_tuple2 = tuple()
print(F't: {type(t)}👉{t}')
print(F'empty_tuple1: {type(empty_tuple1)}👉{empty_tuple1}')
print(F'empty_tuple2: {type(empty_tuple2)}👉{empty_tuple2}')
print('🍀🍀🍀🍀🍀🍀')

# 2、定义单个元素的元组
t1 = ('success')  # 这不是元组，是字符串
print(F't1👉{type(t1)}👉{t1}')
t2 = ('success',)
print(F't2👉{type(t2)}👉{t2}')
print('🍀🍀🍀🍀🍀🍀')

# 3、元组嵌套
t3 = ((1, 2, 3), ('a', 'b', 'c'))
print(F't3👉{type(t3)}👉{t3}')
print(t3[1][2] == 'c')  # True
print(t3[-1][-1] == 'c')  # True
print('🍀🍀🍀🍀🍀🍀')

tuple_tuple = ('8', '张三丰', '8', '8', '张无忌', '8', '白眉鹰王', '8', '8', '紫衫龙王', '8', '金毛狮王', '8')
# 4、查找元素在元组中的索引
print(tuple_tuple.index('白眉鹰王') == 6)
print(tuple_tuple.index('8') == 0)

# 5、count统计数量
print(tuple_tuple.count('8'))

# 6、统计元组中元素数量
print(len(tuple_tuple))
print('🍀🍀🍀🍀🍀🍀')

my_tuple = ('一帆风顺', '双喜临门', '三羊开泰', '四季发财', '五福临门', '六六大顺')
print(type(my_tuple))
# 7、while循环遍历元组
i = 0
while i < len(my_tuple):
    print(F'while: {my_tuple[i]}')
    i += 1

# 8、for循环遍历元组
for e in my_tuple:
    print(F'for: {e}')
print('🍀🍀🍀🍀🍀🍀')

# 9、修改元组
t = (1, 'a', [1, 2, 3])
# TypeError: 'tuple' object doesn't support item deletion
# del t[0]
# TypeError: 'tuple' object does not support item assignment
# t[0] = 9

# 元素里面的列表是可以修改的
print(F'修改前：{t}')
t[2].extend([6, 7, 8])
print(F'修改后：{t}')
